package com.ldk.base.framework.util;

import java.io.FileInputStream;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

/**
 * 属性文件公共方法
 * @author xiangwl
 * @date  2015-05-05
 * @version v1.0
 */
public class PropertiesUtil {
	
	/**
	 * 读取属性文件
	 * @param path 属性文件完整路径
	 * @return Properties 属性对象
	 * @throws Exception
	 */
	public static Properties read(String path) throws Exception{
		if(StringUtils.isEmpty(path)){
			throw new Exception("属性文件路径不能为空");
		}
		Properties props = new Properties();
		try{
			FileInputStream stream = new FileInputStream(path);
			props.load(stream);
		}
		catch(Exception e){
			throw e;
		}
		return props;
	}
	/**
	 * 获取指定属性属性值
	 * @param props 属性对象
	 * @param key 属性Key
	 * @return String 属性值
	 */
	public static String getProperty(Properties props, String key){
		if(props == null)
			return "";
		String value = props.getProperty(key,"");
		
		return value;
	}
}
